package com.example.booklist.advice;

import com.example.booklist.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorAdvice {

    @ExceptionHandler
    public Object handler(Exception e) {
        log.info("Exception异常:{}",e);
        return Result.fail("Exception异常,e:" + e.getMessage());
    }

    @ExceptionHandler
    public Object handler(ArithmeticException e) {
        log.info("ArithmeticException异常:{}",e);
        return Result.fail("ArithmeticException异常,e:" + e.getMessage());
    }

    @ExceptionHandler
    public Object handler(NullPointerException e) {
        log.info("NullPointerException异常:{}",e);
        return Result.fail("NullPointerException异常,e:" + e.getMessage());
    }
}
